package com.ruoyi.com.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.OperateBasicForm;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.com.mapper.ComBusinessClassifyMapper;
import com.ruoyi.com.domain.ComBusinessClassify;
import com.ruoyi.com.service.IComBusinessClassifyService;

/**
 * 业务管理-分类设置Service业务层处理
 *
 * @author sunye
 * @date 2024-12-07
 */
@Service
public class ComBusinessClassifyServiceImpl extends ServiceImpl<ComBusinessClassifyMapper, ComBusinessClassify> implements IComBusinessClassifyService
{
    @Autowired
    private ComBusinessClassifyMapper comBusinessClassifyMapper;

    /**
     * 查询业务管理-分类设置
     *
     * @param classifyId 业务管理-分类设置主键
     * @return 业务管理-分类设置
     */
    @Override
    public ComBusinessClassify selectComBusinessClassifyByClassifyId(Long classifyId)
    {
        return comBusinessClassifyMapper.selectComBusinessClassifyByClassifyId(classifyId);
    }

    /**
     * 查询业务管理-分类设置列表
     *
     * @param comBusinessClassify 业务管理-分类设置
     * @return 业务管理-分类设置
     */
    @Override
    public List<ComBusinessClassify> selectComBusinessClassifyList(ComBusinessClassify comBusinessClassify)
    {
        return comBusinessClassifyMapper.selectComBusinessClassifyList(comBusinessClassify);
    }

    /**
     * 新增业务管理-分类设置
     *
     * @param comBusinessClassify 业务管理-分类设置
     * @return 结果
     */
    @Override
    public int insertComBusinessClassify(ComBusinessClassify comBusinessClassify)
    {
        comBusinessClassify.setCreateTime(DateUtils.getNowDate());
        comBusinessClassify.setUpdateTime(DateUtils.getNowDate());
        return comBusinessClassifyMapper.insertComBusinessClassify(comBusinessClassify);
    }

    /**
     * 修改业务管理-分类设置
     *
     * @param comBusinessClassify 业务管理-分类设置
     * @return 结果
     */
    @Override
    public int updateComBusinessClassify(ComBusinessClassify comBusinessClassify)
    {
        comBusinessClassify.setUpdateTime(DateUtils.getNowDate());
        return comBusinessClassifyMapper.updateComBusinessClassify(comBusinessClassify);
    }

    /**
     * 批量删除业务管理-分类设置
     *
     * @param classifyIds 需要删除的业务管理-分类设置主键
     * @return 结果
     */
    @Override
    public int deleteComBusinessClassifyByClassifyIds(Long[] classifyIds)
    {
        return comBusinessClassifyMapper.deleteComBusinessClassifyByClassifyIds(classifyIds);
    }

    /**
     * 删除业务管理-分类设置信息
     *
     * @param classifyId 业务管理-分类设置主键
     * @return 结果
     */
    @Override
    public int deleteComBusinessClassifyByClassifyId(Long classifyId)
    {
        //查看是否有文章使用
        int count = comBusinessClassifyMapper.selectCountByClassifyId(classifyId);
        if(count>0){
            throw new ServiceException("该分类已被使用，不能删除");
        }
        return comBusinessClassifyMapper.deleteComBusinessClassifyByClassifyId(classifyId);
    }

    /**
     * 置为有效/无效业务管理-分类设置
     *
     */
    @Override
    public int effectiveStatus(OperateBasicForm operateBasicForm)
    {
        return comBusinessClassifyMapper.effectiveStatus(operateBasicForm);
    }
}
